<template>
	<view class="content1">
		<view class="login"></view>
		<view class="uni-form-item uni-column">
			<view class="login_label">租车平台</view>
		</view>
		<view class="uni-form-item uni-column">
			<view>
				<input class="uni-input" v-model="username" focus placeholder="请输入用户名" />
			</view>
		</view>
		<view class="uni-form-item uni-column">
			<view>
				<input class="uni-input" v-model="password" hold-keyboard placeholder="请输入密码" password=true>
			</view>
		</view>
		<view class="uni-form-item uni-column">
			<text class="text1" @click="goregister">立即注册</text>
			<text class="text2" @click="goreset">忘记密码</text>
			<view class="button">
				<button type="primary" @click="goindex">登录</button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				username: '',
				password: '',
			}
		},
		methods: {
			goindex() {
				uni.request({
					url: 'http://192.168.43.190:8080/login',
					method: 'POST',
					data: {
						username: this.username,
						password: this.password
					},
					// header:{
					// 	"Content-Type":"multipart/form-data"
					// },
					success: (res) => {
						// 登录成功，保存令牌
						uni.setStorageSync('token', res.data.token);

						if (res.data.code === 200) {
							uni.showToast({
								title: "登录成功",
								duration: 2000,
								position: 'top'
							});

							setTimeout(() => {
								//跳转到首页或其他页面
								uni.navigateTo({
									url: '/pages/person/person'
								});
							}, 2000)
							console.log(uni.getStorageSync('token'));
						}
					},
					fail: (err) => {
						// 登录失败
						console.error(err);
					}
				});
			},
			// 其他方法...
			goregister() {
				uni.navigateTo({
					url: "/pages/register/register"
				})
			},
			goreset() {
				uni.navigateTo({
					url: "/pages/reset/reset"
				})
			},
		},

	}
</script>

<style lang="scss">
	.content1 {
		padding: 60rpx 30rpx;
		text-align: center;
	}

	.login_label {
		height: 200rpx;
		font-size: 50rpx;
	}

	.uni-input {
		text-decoration: underline;
		height: 50rpx;
		margin: 100rpx;
	}

	.button {
		text-align: center;
		padding: 60rpx 30rpx;

	}

	.text1 {
		margin: 50rpx 100rpx;
	}

	.text2 {
		margin: 0 100rpx;
	}
</style>